import { Button, Form, Input, message } from 'antd';
import React from 'react';
import { Link, withRouter } from 'react-router-dom'
import Layout from '../../../components/layout'
import stores from '../../../stores';
import { Res } from '../../../types/base';
import $http from '../../../utils/require';


const AddCategory = (props: any) => {
    // console.log('Category', props.location.pathname);
    const onfinish = ({ name }: { name: string }) => {
        $http['createCategory']({ userId: stores.User.user._id }, { name }).then((res: { name: string }) => {
            message.success(`[${res.name}]分类添加成功！`);
        }).catch((err: Res) => {
            message.error(err.error);
        })
    }

    return (
        <Layout title="添加分类" subtitle="">
            <Form onFinish={onfinish}>
                <Form.Item name="name" label="分类名称">
                    <Input></Input>
                </Form.Item>
                <Form.Item >
                    <Button type="primary" htmlType="submit">添加分类</Button>
                </Form.Item>

            </Form>
            <Button><Link to="/admin/dashboard">返回 Dashboard</Link></Button>
        </Layout>
    )
}

export default withRouter(AddCategory)
